﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Public;
using System.Data.Objects;

namespace DAL
{
    public class NhanKhauDAL
    {
        public static List<NhanKhauPublic> LoadNhanKhauByMaSHK(int MaSHK)
        {
           string chuoi = "select * from NhanKhau where MaSHK=" + MaSHK;
           var nhankhau = Common.db.ExecuteStoreQuery<NhanKhauPublic>(@chuoi);
           return nhankhau.ToList();
        }
        //public static List<NhanKhauPublic> LoadNhanKhau()
        //{ }
        public static void InsertNhanKhauKS(NhanKhauPublic _nk)
        {
            Nhankhau nk = new Nhankhau();
            nk.HoTen = _nk.HoTen;
            nk.GioiTinh = _nk.GioiTinh;
            nk.NgaySinh = _nk.NgaySinh;
            nk.QuanHe = _nk.QuanHe;
            nk.MaQT = _nk.MaQT;
            nk.MaDT = _nk.MaDT;
            nk.QueQuan = _nk.QueQuan;
            nk.MaSHK = _nk.MaSHK;
            nk.MaKS = _nk.MaKS;
            nk.MaNK = _nk.MaNK;
            nk.MaCT = _nk.MaCT;
            nk.MaTG = _nk.MaTG; 
            nk.MaSHK = nk.MaSHK;
            nk.MaTD = _nk.MaTD;
            nk.CMND = _nk.CMND;
            nk.TenGoiKhac = _nk.TenGoiKhac;
            nk.NgheNghiep = _nk.NgheNghiep;
            Common.db.AddToNhankhaus(nk);
            Common.db.SaveChanges();
        }
        public static NhanKhauPublic LoadMaNK()
        {
            var nk = Common.db.ExecuteStoreQuery<NhanKhauPublic>(@"select Max(MaNK) as MaNK from NhanKhau");
            return nk.ToList()[0];
        }
        public static void UpdateChungTu(int MaCT,int MaNK)
        {
            var nk = Common.db.ExecuteStoreQuery<NhanKhauPublic>(@"update NhanKhau set MaCT=" + MaCT + "where MaNK=" + MaNK);
            Common.db.SaveChanges();
        }
    }
}
